﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace CalculatorLib.Test
{

    [TestClass]
    public class MathLibTestWithMock
    {

        private MathLib _lib;
        private MockRepository mocks;
        private IPiWebService mockedWS;

        [TestInitialize]
        public void SetupLib()
        {
            mocks = new MockRepository();

            mockedWS = mocks.DynamicMock<IPiWebService>();
        }

        [TestMethod]
        public void CircumferenceIsComputedCorrectly()
        {
            Expect.Call(mockedWS.GetPi()).Return(3.1416f);
            _lib = new MathLib(mockedWS);
            mocks.ReplayAll();

            float result = _lib.ComputeCircumference(3f);
            Assert.AreEqual(18.8496f, result);
            mocks.VerifyAll();
        }

        [TestMethod]
        public void MassIsComputedCorrectly()
        {
            Expect.Call(mockedWS.GetGravity("Milano")).Return(9.8f);
            _lib = new MathLib(mockedWS);
            mocks.ReplayAll();

            float result = _lib.CalculateMass(80f, "Milano");
            Assert.AreEqual(8.16f, result, 0.01f);
            mocks.VerifyAll();
        }
    }
}
